<?php

namespace app\jobs;

use app\admin\model\Fields;
use app\lib\MyLog;
use think\facade\Queue;
use think\queue\Job;

/**
 * php think queue:list --queue generateData
 */
class GenerateDataJob
{
    public function generateData(Job $job,$data)
    {
        $data['number'] = intval($data['number']);
        if($data['number'] > 30){
            $number = 30;
        }else{
            $number = $data['number'];
        }
        try{
            echo '生成='.$number;
            Fields::generateDataAll($data['name'],$number);
            $job->delete();
            $data['number'] -= 30;
            echo $data['number'];
            if($data['number'] > 0){
                Queue::push('app\jobs\GenerateDataJob@generateData', $data,'generateData');
            }
        }catch(\Exception $e){
            $job->delete();
            echo $e->getMessage();
            MyLog::error($e,'数据生成失败');
        }
    }
}